package org.example.controller;

import org.example.model.Book;
import org.example.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    /**
     * GET api/book/queryAsDict
     * 查询图书数据字典
     *{
     *   "success" : true,
     *   "code" : "200",
     *   "message" : "操作成功",
     *   "data" : [ {
     *     "dictionaryTagKey" : "1",
     *     "dictionaryTagValue" : "高等数学",
     *     "author" : "马拉司机",
     *     "price" : 115.20
     *   }]
     *}
     */
    @GetMapping("/queryAsDict")
    public Object queryAsDict(){
        List<Book> list=bookService.queryAsDict();
        return list;
    }

    @GetMapping("/query")
    public Object query( Book book){
        List<Book> list=bookService.query(book);
        return list;
    }
    @GetMapping("/queryById")
    public Object queryById(Integer id){
        Book book=bookService.queryById(id);
        return book;
    }
    @PostMapping("/update")
    public Object update(@RequestBody Book book){
        int n=bookService.update(book);
        return null;
    }
    @GetMapping("/delete")
    public Object delete(@RequestParam("ids") List<Integer> ids){
        int a=bookService.delete(ids);
        return null;
    }
}
